<?php
defined('IN_SITE') or exit('Access Denied');

require_once MOD_ROOT.'movie/movie.class.php';
$movie = new movie();
require_once MOD_ROOT.'attachment/attachment.class.php';
$attachment = new attachment($module, $catid);
$C = subcat('movie');

switch($action)
{
    default:
		
		if($movieid){
			// 如果参数是自定义名称
			if(!$movieid && $prefix){
				$result = $db->get_one("select `movieid` from ".DB_PRE."movie where prefix = '$prefix'");
				$movieid = $result['movieid'];
				unset($result);
			} 
			
			// 主要获取该文章的栏目所在信息，例如详细页模板等等
			require_once MOD_ROOT.'movie/movie.class.php';
			$movie = new movie();
			$r = $movie->get($movieid);
			$C = cache_read('category_'.$r['catid'].'.php');
		
			
			// 获取该文章的所有内容信息
			require_once CACHE_MODEL_PATH.'movie_output.class.php';
			$out = new movie_output();
			$data = $out->get($r);
			extract($data);
		
			// 设置文章的头部信息、关键字等
			$title = strip_tags($title);
			$head['title'] = $title.'_'.$C['catname'].'_'.$SETTING['sitename'];
			$head['keywords'] = str_replace(' ', ',', $r['keywords']);
			$head['description'] = $r['description'];
			 
			if(!$C['defaultchargepoint'] && !$r['readpoint'])
			{
				header('Last-Modified: '.gmdate('D, d M Y H:i:s', $r['updatetime']).' GMT');
				header('Expires: '.gmdate('D, d M Y H:i:s', $r['updatetime']+CACHE_PAGE_CONTENT_TTL).' GMT');
				header('Cache-Control: max-age='.CACHE_PAGE_CONTENT_TTL.', must-revalidate');
			}
			include template('view.html','movie');
			cache_page(CACHE_PAGE_CONTENT_TTL);
		}
		else{
			
			include template('index.html','movie');
		}
	break; 
	
	case 'tag':
		$keyword = load('keyword.class.php','keyword');
		$data = $keyword->get($tag);
		if(!$data) showmessage("TAG: $tag 不存在！");
		$keyword->hits($tag);
		extract($data);
		
		// 所有tag标签连成的字符串，用于sql查询的时候where in()
		$data2 = $db->select("select `tag` from table_movie_tag t");
		foreach($data2 as $k=>$v){
			$tags .= !$tags ? $v['tag'] : ','.$v['tag'];
		}
		
		$head['title'] = $tag.'-'.$SETTING['sitename'];
		
		include template('tag.html');
	break;
	
	case 'add':
		if($dosubmit)
		{
			$info['catid'] = $catid;
			$info['status'] = 99;
			if(isset($info['inputtime'])) $info['updatetime'] = $info['inputtime'];
			$movieid = $movie->add($info,$cat_selected);
			if($movieid) showmessage('发布成功！', url("?module=$module&action=add"));
		}
		else{
			$modelid = 55;
			require_once 'form.class.php';
			require CACHE_MODEL_PATH.'movie_form.class.php';
			$movie_form = new movie_form($modelid);
			$data['catid'] = $catid;
			$forminfos = $movie_form->get($data);
			
			//dump($forminfos);
			include template('add.html','movie');
		}
	break;
	
}
?>